package web.play.rss.util.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;



public class SpiderDAO {
	

	public boolean addStockNum(String num,String name,String type){
		boolean isadd = false ;

		Connection con = null;
		PreparedStatement ps = null;
		String sql = "insert ignore into Stock (StockNum, StockName, StockType, StockAddr, StockActive)values( ?, ?, ?, '', 2)";
		try {
			con = new DBConnSourceByStruts().getConnection();
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		try{
			
			ps = con.prepareStatement(sql);
			ps.setString(1, num);
			ps.setString(2, name);
			ps.setString(3, type);
			
			ps.execute();
			
			isadd = true;
			
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return isadd;
	}
	
	public String getStock(){
		String rtnStr = "";
		String sql = "select * from Stock";
		Connection con = null;
		try {
			con = new DBConnSourceByStruts().getConnection();
		} catch (SQLException e1) {
			e1.printStackTrace();
		}

		PreparedStatement ps = null;
		try{
			
			ps = con.prepareStatement(sql);
			
			ResultSet rs = ps.executeQuery();
			
			while(rs.next()){
				System.out.println(rs.getString(1) +"  "+rs.getString(2) +"   " + rs.getString(3));
			}
			
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return rtnStr;
	}
	

}
